<?php
require_once 'dbconfig.php';
$i = 0;
$output = array();
	$query = <<<END
		SELECT *
		FROM  organizations; 
END;

	$result = mysql_query ( $query, $connection );
	$size = mysql_num_rows($result); 

	$i = 0;
	while ( $row = mysql_fetch_array ( $result ) ) {
		$id = $row['orgID'];
		$orgName = $row['orgName'];
		//$name = $row[2]." ".$row[3];
		$phone_number = "(".$row['areaCode'].")".$row['prefix']."-".$row['lineNumber'];
		$fax_number = "(".$row['faxAreaCode'].")".$row['faxPrefix']."-".$row['faxLineNumber'];
		$street_address = $row['streetAddress']." ".$row['streetAddress2'];
		$city_state_zip = $row['city'].", ".$row['state']." ".$row['zipCode'];
		$website = $row['websiteAddress'];
		$httpPresent = strpos($website, "http://");
		if($httpPresent === false){
			$website = "http://" . $website;
		}
		$email = $row['email'];
		//$times = $row[17];
		//$add_info = $row[18];
		$lat = $row['lat'];
		$lng = $row['lng'];
		$category =$row['category'];
 
        $infobox = <<<END
		<div id="contact$i" class="infowindow">
			<div id="streetview"></div>
			<div class="infowindow">
				<div id="orgName" class="org bold" >$orgName</div>
				<div id="address1" class="address" >$street_address</div>
				<div id="address2" class="empty">$city_state_zip</div>
				<div id="phone" class="phone" >Phone: $phone_number</div>
				<div id="fax" class="fax" >Fax: $fax_number</div>
				<div id="website" class="website" ><a href="$website" target="_blank" >Go to website</a></div>
				<div id="email" class="email" ><a href="mailto:$email" target="_blank" >$email</a></div>
				<div id="edit" class="button" ><a href="edit_info.php?id=$id">Edit info</a></div>
			</div>
		</div>
END;
		
		$info = array('id' => $id, 'phone' => $phone_number , 'fax' => $fax_number, 
				'address1' => $street_address, 'address2' => $city_state_zip , 'website'=>$website,
				'email' => $email, 'lat' => $lat, 
				'lng' => $lng, 'category' => $category ,'infobox' => $infobox, 'orgName' => $orgName);
		
		array_push($output, $info);
		
		$i++;
	}
	echo json_encode($output);
//}
?>